import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controller/home_controller.dart';

class HomePageText extends StatelessWidget {
  const HomePageText({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(HomeController());
    final HomeController controller = Get.find<HomeController>();
    return Scaffold(
      appBar: AppBar(title: const Text('首页33')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Obx(() => Text(
                '姓名：${controller.user.value.name}, 年龄：${controller.user.value.age}')),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => controller.updateUserName('Jerry'),
              child: const Text('改名为Jerry'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: controller.incrementAge,
              child: const Text('年龄+1'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () async {
                final result = await Get.toNamed('/second',
                    arguments: {'userId': 42, 'isAdmin': true});
                if (result != null) {
                  Get.snackbar('回传参数', result.toString());
                }
              },
              child: const Text('进入第二页传参数'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => Get.toNamed('/listen_demo'),
              child: const Text('监听示例'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => Get.toNamed('/counter_setstate'),
              child: const Text('setState 示例'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => Get.toNamed('/getbuilder_demo'),
              child: const Text('GetBuilder 示例'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => Get.toNamed('/getbuilder_stateless_demo'),
              child: const Text('GetBuilder 无状态组件示例'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => Get.toNamed('/getview_demo'),
              child: const Text('GetView 示例'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => Get.toNamed('/getx_ui_demo'),
              child: const Text('GetX UI/Utils 示例'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () => Get.toNamed('/getx_mixin_demo'),
              child: const Text('GetX Mixin 示例'),
            ),
          ],
        ),
      ),
    );
  }
}
